
import sympy
import sympy.integrals.quadrature
import numpy as np

x = sympy.symbols('x')
expr = sympy.cos(x)
func = sympy.lambdify((x),expr,'numpy')


def mt_int(f,a,b):
    sum = 0
    N = 300
    for i in range(N):
        x = np.random.rand()*(b-a)+a
        #print(x)
        sum += f(x)
    sum = sum/N*(b-a)
    return sum

I = sympy.integrate(expr,(x,0,1)).evalf()
print(I)
I = mt_int(func,0,1)
print(I)
